{% extends 'base.html' %}
{% load static %}
{% block css %}
    <link rel="stylesheet" type="text/css" href="{% static 'assets/select2/select2.css' %}" />
{% endblock %}
{% block title %}
    添加通用工单
{% endblock %}
{% block page-title %}
    添加通用工单
{% endblock %}
{% block page-content %}
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">添加通用工单</h3>
                </div>
                <div class="panel-body">
                    <form method="post" class="form-horizontal">
                        <div class="form-group web">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="work_title" name="work_title" autocomplete="off">
                            </div>
                        </div>
                        <div class="form-group web">
                            <label class="col-sm-2 control-label">工单类型</label>
                            <div class="col-sm-10">
                                <select data-placeholder="选择工单类型"
                                        class="select2"
                                        id="work_type" name="work_type">
                                    {% for tag in tags %}
                                        <option value="{{ tag }}">{{ tag }}</option>
                                    {% endfor %}
{#

                                </select>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label">工单描述：</label>
                            <div class="col-sm-10">

                                <textarea cols="100" rows="3" name="content" id="content" placeholder="工单内容描述"></textarea>

                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary btn-submit" type="button">提交</button>
                                <input class="btn btn-white" type="reset" value="取消">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block js %}

    <script src="{% static 'assets/sweet-alert/sweet-alert.min.js' %}"></script>

    <script src="{% static 'assets/select2/select2.min.js' %}" type="text/javascript"></script>
    <script>
          jQuery(".select2").select2({
            width: '100%'
        });
    </script>
    <script>
     //监听提交按钮点击事件
        $('.btn-submit').click(function () {

            var work_title = $('#work_title').val();
            var content = $('#content').val();
            var work_type = $('#work_type').val();
            if(work_title === '' || work_type === '' || content === ''){
                swal({
                    title: '警告',
                    text: '表单不能为空，请填充完整表单!',
                    type: 'warning',
                });
                return false
            }
            $.ajax({
                 type: 'POST',
                 url: '/workflow/apply/',
                 data: {work_title: work_title , content: content, work_type: work_type},
                 success: function (result) {
                    if(result['code'] === 0){
                        window.location.href = '/workflow/orderlist/';
                    }
                }
            })
        })
    </script>
{% endblock %}
